package com.linkage.bss.crm.packagemgr.bmo.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Map.Entry;


import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import com.linkage.bss.commons.dao.Page;
import com.linkage.bss.commons.util.JsonUtil;
import com.linkage.bss.crm.packagemgr.bmo.IPackageManagerBMO;
import com.linkage.bss.crm.packagemgr.dao.IAreaDAO;
import com.linkage.bss.crm.packagemgr.dao.IPackageManagerDAO;
import com.linkage.bss.crm.packagemgr.dao.IPackageObjDAO;
import com.linkage.bss.crm.packagemgr.dao.IPackageUtilDAO;
import com.linkage.bss.crm.packagemgr.dto.PackInfoDto;
import com.linkage.bss.crm.packagemgr.model.ActionOrderItem;
import com.linkage.bss.crm.packagemgr.model.ActionParameter;
import com.linkage.bss.crm.packagemgr.model.Package;
import com.linkage.bss.crm.packagemgr.model.PackageObject;
import com.linkage.bss.crm.packagemgr.model.PackageParameter;
import com.linkage.bss.crm.packagemgr.model.ParameterActionRela;
import com.linkage.bss.crm.packagemgr.model.ParameterMapRela;
import com.linkage.bss.crm.packagemgr.util.Constant;

/**
 *
 * 包管理 BMO层
 *
 * @author sgl
 * @date 2013-4-16
 * @version 1.0
 */
public class PackageManagerBMOImpl implements IPackageManagerBMO {

	private IPackageManagerDAO packageManagerDAO;
	private IPackageObjDAO packageObjDAO;
	private IAreaDAO areaDAO;
	private IPackageUtilDAO packageUtilDAO;

	public List<Package> getPackageByCond(Map map, Page page) {
		return packageManagerDAO.getPackageByCond(map, page);
	}

	public int getPackageByCondCount(Map map) {
		return packageManagerDAO.getPackageByCondCount(map);
	}

	public List<ActionOrderItem> getActionOrderItemByPackId(Long packageID) {

		List<ActionOrderItem> actionOrderItemList = getPackageObjDAO().queryActionOrderItemByPackId(packageID);
		if (null != actionOrderItemList) {
			for (ActionOrderItem actionOrderItem : actionOrderItemList) {
				//封装条目参数。
				List<ActionParameter> apList = getActionParameterByItemId(Long.valueOf(actionOrderItem
								.getActionItemId()));
				actionOrderItem.setActionItemParameterList(apList);
			}
		}
		return actionOrderItemList;

	}

	public List<ActionParameter> getActionParameterByItemId(Long itemId) {
		List<ActionParameter> apList = getPackageObjDAO().getActionParameterByAID(itemId);
		if (null != apList) {
			for (ActionParameter actionParam : apList) {
				Long paramId = actionParam.getParameterId();
				//参数决定动作
				List<ParameterActionRela> paramActionRelaList = getPackageObjDAO().queryParamActionRelaByParamId(
								paramId);
				actionParam.setParameterActionRelaList(paramActionRelaList);

				//动作参数与包参数映射关系
				ParameterMapRela parameterMapRela = getPackageObjDAO().queryParamMapRelaByParamId(paramId);
				if (null != parameterMapRela) {
					actionParam.setPackageParameterId(parameterMapRela.getPackageParameterId());
				}
			}
		}
		return apList;
	}

	public List<ParameterActionRela> getParamActionRelaByParamId(Long paramId) {
		List<ParameterActionRela> paramActionRelaList = getPackageObjDAO().queryParamActionRelaByParamId(paramId);
		return paramActionRelaList;
	}

	public Package getPackageById(Long packageID) {

		Map<String, Object> map = new HashMap<String, Object>();
		map.put("packageId", packageID);

		//获取包基本信息
		Package pack = getPackageManagerDAO().getPackageById(packageID);
		// 获取包对象根据包ID
		List<PackageObject> packageObjList = getPackageObjDAO().queryPackgeObject(map);

		pack.setPackageObjList(packageObjList);

		//获取包条目信息
		List<ActionOrderItem> actionOrderItemList = getActionOrderItemByPackId(packageID);
		pack.setActionOrderItemList(actionOrderItemList);

		// 获取包参数
		List<PackageParameter> packageParameterList = getPackageManagerDAO().getPackageParamByID(packageID);
		pack.setPackageParameterList(packageParameterList);

		return pack;
	}

	/**
	 * 根据包ID删除完整性，包信息
	 * @param packageId [参数说明]
	 *
	 * @return void [返回类型说明]
	 * @exception throws [违例类型] [违例说明]
	 * @see [类、类#方法、类#成员]
	 */
	public void delPackageByPackId(Long packageId) {

		packageObjDAO.delParameterMapRelaByPackId(packageId);
		packageObjDAO.delParameterActionRelaByPackId(packageId);
		packageObjDAO.delPackageParameterByPackId(packageId);
		packageObjDAO.delActionParameterByPackId(packageId);
		packageObjDAO.delActionOrderItemByPackId(packageId);
		packageObjDAO.deletePackgeObj(packageId, null);
	}

	public boolean savePackage(Package pack) {
		Map msgMap = new HashMap();
		boolean result = validatePackage(pack, msgMap);
		if (!result) {
			return false;
		}

		//入库前初始化各主键
		relocatePackageSeq(pack, Constant.PACK_OPERATE_ADD);

		//1.先保存包基本信息。
		getPackageManagerDAO().insertPackageInfo(pack);
		//2. 保存包参与对象。
		savePackageObj(pack.getPackageObjList());
		//3. 保存包的参数信息。
		savePackageParameter(pack.getPackageParameterList());
		//4. 保存包的条目信息。
		saveActionItem(pack.getActionOrderItemList());
		//5. 保存参数决定动作信息。
		saveParameterActionRela(pack.getParamActionRelaList());

		return true;
	}

	public boolean updatePackage(Package pack, Map operateMap) {
		//更新包基本信息。
		getPackageManagerDAO().updatePackageInfo(pack);
		String operate = (String) operateMap.get("operate");

		//临时方案：删除包其他信息后，做新增
		//入库前初始化各主键

		relocatePackageSeq(pack, operate);

		delPackageByPackId(pack.getPackageId());
		//2. 保存包参与对象。
		savePackageObj(pack.getPackageObjList());

		//3. 保存包的参数信息。
		savePackageParameter(pack.getPackageParameterList());

		//4. 保存包的条目信息。
		saveActionItem(pack.getActionOrderItemList());

		//5. 保存参数决定动作信息。
		saveParameterActionRela(pack.getParamActionRelaList());

		//		//更新包参数信息
		//		updatePackageParam(pack.getPackageId(), pack.getPackageParameterList());
		//
		//		Object[] addItems = (Object[])operateMap.get("add");
		//		Object[] modifyItems = (Object[])operateMap.get("modify");
		//		Object[] delItems = (Object[])operateMap.get("del");
		//
		//		//构造存在的包条目
		//		List<PackageObject> objList = pack.getPackageObjList();
		//		List<ActionOrderItem> actionItemList = pack.getActionOrderItemList();
		//		//新增条目
		//		if (addItems != null && addItems.length != 0) {
		//			for (ActionOrderItem actionItem : actionItemList) {
		//				for (int i =0;i < addItems.length; i++) {
		//					if (actionItem.getActionItemId().equals(addItems[i].toString())) {
		////						relocateActionOrderItemSeq(actionItem);
		//						saveActionOrderItem(actionItem);
		//					}
		//				}
		//
		//			}
		//		}
		//		if (modifyItems != null && modifyItems.length != 0) {
		//
		//		}
		//		//删除条目
		//		if (delItems != null && delItems.length != 0) {
		//			List<ActionOrderItem> delList = getActionOrderItemByPackId(pack.getPackageId());
		//			for (ActionOrderItem actionItem : delList) {
		//				for (int i =0;i < delItems.length; i++) {
		//					if (actionItem.getActionItemId().equals(delItems[i].toString())) {
		//						deleteActionOrderItem(actionItem);
		//					}
		//				}
		//			}
		//			//包对象处理
		//			Map<String, Object> map = new HashMap<String, Object>();
		//			map.put("packageId", pack.getPackageId());
		////			List<PackageObject> oldObjList = getPackageObjDAO().queryPackgeObject(map);
		////			List<PackageObject> objList = pack.getPackageObjList();
		//
		//		}

		return true;
	}

	private void savePackageParameter(List<PackageParameter> list) {
		if (list == null || list.size() == 0) {
			return;
		}
		//循环保存包参数信息
		for (PackageParameter packageParameter : list) {
			getPackageManagerDAO().insertPackageParameter(packageParameter);
		}
	}

	/**
	 * 批量保存条目信息
	 * <功能详细描述>
	 * @param list [参数说明]
	 *
	 * @return void [返回类型说明]
	 * @exception throws [违例类型] [违例说明]
	 * @see [类、类#方法、类#成员]
	 */
	private void saveActionItem(List<ActionOrderItem> list) {
		if (list == null || list.size() == 0) {
			return;
		}

		for (ActionOrderItem item : list) {
			getPackageObjDAO().insertActionItem(item);
			saveActionParam(item.getActionItemParameterList());
		}

	}

	/**
	 * 批量保存条目参数信息
	 * @param list [参数说明]
	 *
	 * @return void [返回类型说明]
	 * @exception throws [违例类型] [违例说明]
	 * @see [类、类#方法、类#成员]
	 */
	private void saveActionParam(List<ActionParameter> list) {

		if (list == null || list.size() == 0) {
			return;
		}
		for (ActionParameter actionParameter : list) {
			getPackageObjDAO().insertActionParameter(actionParameter);
			Long ppID = actionParameter.getPackageParameterId();
			if (ppID != null) {
				getPackageObjDAO().insertParameterMapRela(ppID, Long.valueOf(actionParameter.getParameterId()));
			}

		}
	}

	private void saveParameterActionRela(List<ParameterActionRela> list) {
		if (list == null || list.size() == 0) {
			return;
		}

		for (ParameterActionRela parameterActionRela : list) {
			getPackageObjDAO().insertParameterActionRela(parameterActionRela);
		}
	}

	private void savePackageObj(List<PackageObject> list) {
		if (list == null || list.size() == 0) {
			return;
		}
		for (PackageObject packageObject : list) {
			getPackageObjDAO().insertPackageObj(packageObject);
		}

	}

	/**
	 * 入库前校验，包数据
	 *
	 * @return void [返回类型说明]
	 * @exception throws [违例类型] [违例说明]
	 * @see [类、类#方法、类#成员]
	 */
	private boolean validatePackage(Package pack, Map msgMap) {
		List<PackageObject> objList = pack.getPackageObjList();
		List<ActionOrderItem> itemList = pack.getActionOrderItemList();
		List<PackageParameter> parameterList = pack.getPackageParameterList();

		if (objList == null || objList.isEmpty()) {
			msgMap.put("result", false);
			msgMap.put("msg", "包对象不能为空");
			return false;
		}
		if (itemList == null || itemList.isEmpty()) {
			msgMap.put("result", false);
			msgMap.put("msg", "包条目不能为空");
			return false;
		}
		return true;
	}

	/**
	 * 设置包对象各序列
	 * @param pack [参数说明]
	 *
	 * @return void [返回类型说明]
	 * @exception throws [违例类型] [违例说明]
	 * @see [类、类#方法、类#成员]
	 */
	private void relocatePackageSeq(Package pack, String type) {
		Map<Long, Long> packParamIdMap = new HashMap<Long, Long>();
		Map<String, Long> actionItemIdMap = new HashMap<String, Long>();
		Map<Long, Long> acitonParamIdMap = new HashMap<Long, Long>();

		Long packageId = null;
		if (Constant.PACK_OPERATE_ADD.equals(type) || Constant.PACK_OPERATE_COPYNEW.equals(type)) {
			packageId = packageUtilDAO.findSEQNextVal(Constant.SEQ_PACKAGE_ID);
			pack.setPackageId(packageId);
		}
		if (Constant.PACK_OPERATE_MODIFY.equals(type)) {
			packageId = pack.getPackageId();
		}

		Map<String, String> objNumbermap = new HashMap<String, String>();
		List<PackageObject> objList = pack.getPackageObjList();
		List<ActionOrderItem> itemList = pack.getActionOrderItemList();
		List<PackageParameter> parameterList = pack.getPackageParameterList();
		List<ParameterActionRela> paramActionRelaList = pack.getParamActionRelaList();
		//包对象
		for (PackageObject object : objList) {
			Long objNumber = packageUtilDAO.findSEQNextVal(Constant.SEQ_PACKAGE_OBJECT_NUMBER);
			//封装临时对象编号与seq
			if (!objNumbermap.containsKey(object.getObjectNumber())) {
				objNumbermap.put(object.getObjectNumber(), objNumber.toString());
			}
			object.setObjectNumber(objNumber.toString());
			object.setPackageId(packageId.toString());

		}
		//包参数
		if (parameterList != null && !parameterList.isEmpty()) {
			//包参数
			for (PackageParameter parameter : parameterList) {
				Long parameterId = packageUtilDAO.findSEQNextVal(Constant.SEQ_PACKAGE_PARAMETER_ID);
				Long packParamId = parameter.getParameterId();
				parameter.setParameterId(parameterId);
				parameter.setPackageId(packageId);
				//将前台的包参数ID与对应的后台包参数ID保存起来
				packParamIdMap.put(packParamId, parameterId);
			}
		}

		//包动作条目
		for (ActionOrderItem actionItem : itemList) {
			//先找出并设置此条目的动作参数
			//			setActionParamList(actionItem, actionParameterList);

			String tempActionItemId = actionItem.getActionItemId();
			Long actionItemId = packageUtilDAO.findSEQNextVal(Constant.SEQ_PACKAGE_ACTION_ITEM_ID);
			actionItem.setActionItemId(String.valueOf(actionItemId));
			actionItem.setPackageId(packageId);
			actionItem.setPartobjNumber(objNumbermap.get(actionItem.getPartobjNumber()));
			actionItem.setEffectobjNumber(objNumbermap.get(actionItem.getEffectobjNumber()));
			actionItemIdMap.put(tempActionItemId, actionItemId);
			relocateActionParamSeq(actionItem, packParamIdMap, acitonParamIdMap);
		}

		//参数决定动作
		if (paramActionRelaList != null && paramActionRelaList.size() != 0) {
			for (ParameterActionRela paramActionRela : paramActionRelaList) {
				Long actionItemId = actionItemIdMap.get(paramActionRela.getActionItemId());
				paramActionRela.setActionItemId(String.valueOf(actionItemId));
				Long actionParamId = acitonParamIdMap.get(paramActionRela.getParameterId());
				paramActionRela.setParameterId(actionParamId);
			}
		}

	}

	//从所有的动作参数中筛选出该动作条目的
	private void setActionParamList(ActionOrderItem actionItem, List<ActionParameter> actionParameList) {
		if (null == actionItem || null == actionParameList) {
			return;
		}

		List<ActionParameter> actionParams = new ArrayList<ActionParameter>();
		for (ActionParameter actionParam : actionParameList) {
			if (actionItem.getActionItemId().equals(actionParam.getActionItemId())) {
				actionParams.add(actionParam);
			}
		}
		if (actionParams.size() > 0) {
			actionItem.setActionItemParameterList(actionParams);
		}
	}

	private void relocateActionParamSeq(ActionOrderItem actionItem, Map<Long, Long> packParamIdMap,
					Map<Long, Long> acitonParamIdMap) {
		if (null == actionItem || null == actionItem.getActionItemParameterList()) {
			return;
		}

		//转化条目ID和参数ID，同时将前台的条目参数转成后台用的条目参数
		List<ActionParameter> actionParams = actionItem.getActionItemParameterList();
		if (null != actionParams && actionParams.size() > 0) {
			for (ActionParameter actionParam : actionParams) {
				Long parameterId = packageUtilDAO.findSEQNextVal(Constant.SEQ_PACKAGE_PARAMETER_ID);
				Long paramId = actionParam.getParameterId();
				actionParam.setParameterId(parameterId);
				actionParam.setActionItemId(String.valueOf(actionItem.getActionItemId()));
				//前台参数ID与后台参数ID映射关系
				acitonParamIdMap.put(paramId, parameterId);
				if (null != actionParam.getPackageParameterId()) {
					if (packParamIdMap != null) {
						Long packageParameterId = packParamIdMap.get(actionParam.getPackageParameterId());
						actionParam.setPackageParameterId(packageParameterId);
					} else {
						//TODO 数据异常，需要处理
						actionParam.setPackageParameterId(null);
					}
				}
			}
		}

		//		List objs = actionItem.getActionItemParameterList();
		//		List<ActionParameter> actionParams = new ArrayList<ActionParameter>();
		//		for (Object obj : objs) {
		//			ActionParameter actionParam = (ActionParameter) JsonUtil.getObject(JsonUtil.getJsonString(obj),
		//							ActionParameter.class);
		//			Long parameterId = packageUtilDAO.findSEQNextVal(Constant.SEQ_PACKAGE_PARAMETER_ID);
		//			Long paramId = actionParam.getParameterId();
		//			actionParam.setParameterId(parameterId);
		//			actionParam.setActionItemId(String.valueOf(actionItem.getActionItemId()));
		//			acitonParamIdMap.put(paramId, parameterId);
		//			if (null != actionParam.getPackageParameterId()) {
		//				if (packParamIdMap != null) {
		//					Long packageParameterId = packParamIdMap.get(actionParam.getPackageParameterId());
		//					actionParam.setPackageParameterId(packageParameterId);
		//				} else {
		//					//TODO 数据异常，需要处理
		//					actionParam.setPackageParameterId(null);
		//				}
		//			}
		//			actionParams.add(actionParam);
		//		}
		//		actionItem.setActionItemParameterList(actionParams);
	}

	public IPackageObjDAO getPackageObjDAO() {
		return packageObjDAO;
	}

	private void updatePackageObj(List<PackageObject> list) {
		for (PackageObject packageObject : list) {
			getPackageObjDAO().updatePackageObj(packageObject);
		}

	}

	/**
	 * 更新包参数信息
	 * <功能详细描述>
	 * @param packageId
	 * @param packageParameterList [参数说明]
	 *
	 * @return void [返回类型说明]
	 * @exception throws [违例类型] [违例说明]
	 * @see [类、类#方法、类#成员]
	 */
	private void updatePackageParam(Long packageId, List<PackageParameter> packageParameterList) {

		getPackageManagerDAO().delPackageParamByPackage(packageId);
		for (PackageParameter packageParameter : packageParameterList) {
			getPackageManagerDAO().insertPackageParameter(packageParameter);
		}

	}

	private void deleteActionParam(List<ActionParameter> list) {

		for (ActionParameter param : list) {
			getPackageObjDAO().deleteParamRela(param.getParameterId());
			getPackageObjDAO().deleteParamMap(param.getParameterId());
		}

	}

	private void updateActionOrderItem(List<ActionOrderItem> actionOrderItemList) {
		for (ActionOrderItem actionOrderItem : actionOrderItemList) {
			getPackageObjDAO().updateActionOrderItem(actionOrderItem);

			deleteActionParam(actionOrderItem.getActionItemParameterList());

			getPackageObjDAO().deleteActionParam(actionOrderItem.getActionItemId());
			saveActionParam(actionOrderItem.getActionItemParameterList());

		}

	}

	private void deleteActionOrderItem(ActionOrderItem actionOrderItem) {
		//删除参数关联关系
		deleteActionParam(actionOrderItem.getActionItemParameterList());
		//参数本身
		getPackageObjDAO().deleteActionParam(actionOrderItem.getActionItemId());

		//删除条目本身
		getPackageObjDAO().deleteActionOrderItem(Long.valueOf(actionOrderItem.getActionItemId()));

	}

	/**
	 * 修改时保存新增条目
	 * @param actionOrderItem [参数说明]
	 *
	 * @return void [返回类型说明]
	 * @exception throws [违例类型] [违例说明]
	 * @see [类、类#方法、类#成员]
	 */
	private void saveActionOrderItem(ActionOrderItem actionOrderItem) {

		getPackageObjDAO().insertActionItem(actionOrderItem);
		saveActionParam(actionOrderItem.getActionItemParameterList());
	}

	public void setPackageObjDAO(IPackageObjDAO packageObjDAO) {
		this.packageObjDAO = packageObjDAO;
	}

	public IPackageManagerDAO getPackageManagerDAO() {
		return packageManagerDAO;
	}

	public IAreaDAO getAreaDAO() {
		return areaDAO;
	}

	public void setAreaDAO(IAreaDAO areaDAO) {
		this.areaDAO = areaDAO;
	}

	public void setPackageManagerDAO(IPackageManagerDAO packageManagerDAO) {
		this.packageManagerDAO = packageManagerDAO;
	}

	public void setPackageUtilDAO(IPackageUtilDAO packageUtilDAO) {
		this.packageUtilDAO = packageUtilDAO;
	}

	public PackInfoDto queryPackInfoByPackId(Long packId) {

		PackInfoDto packInfoDto = new PackInfoDto();
		packInfoDto.setPackId(packId);

		Map<String, Object> map = new HashMap<String, Object>();
		map.put("packageId", packId);

		// 1. 根据包ID查询包中所有对象
		// 获取包对象根据包ID
		List<PackageObject> packObjects = getPackageObjDAO().queryPackgeObject(map);

		packInfoDto.setPackObjects(packObjects);

		// 2. 包动作及动作参数
		//获取包条目信息
		List<ActionOrderItem> actions = getActionOrderItemByPackId(packId);

		packInfoDto.setActions(actions);

		// 3. 包参数

		List<PackageParameter> packParams = getPackageManagerDAO().getPackageParamByID(packId);
		// 设置包参数
		packInfoDto.setPackParams(packParams);

		// 4.参数与动作关系

		List<ParameterActionRela> paramActionRelas = getPackageObjDAO().queryParameterActionRelasByPackId(packId);
		packInfoDto.setParamActionRelas(paramActionRelas);

		// 5.参数与参数关系
		List<ParameterMapRela> paramMapRelas = getPackageObjDAO().queryParameterMapRelasByPackId(packId);
		packInfoDto.setParamMapRelas(paramMapRelas);

		
		// 6.计算包对应对应的参数
		calculateActionInfo(packInfoDto);
		
		return packInfoDto;
	}
	
	/* @createDt 2013-6-19 上午11:44:58
	 * @param packInfoDto
	 */
	private void calculateActionInfo(PackInfoDto packInfoDto) {
		Map<String, JSONObject> map = new HashMap<String, JSONObject>();
		// 对于其中每一个ACTION进行处理
		List<ParameterActionRela> paramActionRelas = packInfoDto.getParamActionRelas();
		if(paramActionRelas == null || paramActionRelas.isEmpty()) return;
		
		Map<Object, List<Object>> paramMap = new HashMap<Object, List<Object>>();
		// 遍历每一个参数动作
		for(ParameterActionRela rela : paramActionRelas){
			// 按ActionId进行分组
			String actionItemId = rela.getActionItemId();
			String key = actionItemId + "_" + rela.getRelaType();
			putToMapList(paramMap, key, rela);
		}
		
		if(paramMap == null || paramMap.isEmpty()) return;

		// 对于分组完成的进行二次封装
		for(Entry<Object, List<Object>> entry : paramMap.entrySet()){
			String key = (String) entry.getKey();
			Long actionItemId = Long.valueOf((key.split("_")[0]));
			String relaType = key.split("_")[1];
			List<Object> list = entry.getValue();
			if(list == null || list.isEmpty()) continue;
			JSONObject json = new JSONObject();
			json.elementOpt("actionId", actionItemId ,JsonUtil.NUMBER_NULL_JSONCONF);
			json.elementOpt("relaType", relaType ,JsonUtil.NUMBER_NULL_JSONCONF);
			Set<Long> paramIdsList = new HashSet<Long>();
			Map<Object, List<Object>> tmpMap = new HashMap<Object, List<Object>>();
			// 把grpId相同的分成一组
			for(Object object : list){
				ParameterActionRela rela = (ParameterActionRela) object;
				paramIdsList.add(rela.getParameterId());
				putToMapList(tmpMap, rela.getGrpId(), rela);
			}
			json.elementOpt("parameterIds", paramIdsList ,JsonUtil.NUMBER_NULL_JSONCONF);
			JSONArray jsonArray = new JSONArray();
			for(Entry<Object, List<Object>> tmpEntry : tmpMap.entrySet()){
				jsonArray.add(tmpEntry.getValue());
			}
			json.elementOpt("paramterRelas",jsonArray, JsonUtil.NUMBER_NULL_JSONCONF);
			map.put(key, json);
		}
		packInfoDto.setControls(map);
	}
	
	/**
	 * @createDt 2013-6-19 下午2:32:27
	 * @param paramMap
	 * @param actionItemId
	 * @param rela
	 */
	private void putToMapList(Map<Object, List<Object>> paramMap, Object key, Object rela) {
		if(paramMap.containsKey(key)){
			paramMap.get(key).add(rela);
		} else {
			List<Object> list = new ArrayList<Object>();
			list.add(rela);
			paramMap.put(key, list);
		}
	}

	public void delPackageAllById(Long packageId) {
		this.delPackageByPackId(packageId);
		getPackageManagerDAO().delPackageById(packageId);

	}
}
